<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class admin_panel extends CI_Controller {

	var $data;

	public function __construct(){
		parent::__construct();

		$this->output->enable_profiler(false);

		$this->load->model('account');

		if(!$this->account->validate_cookie()){
			$this->session->set_flashdata('error', 'Anda tidak mempunyai akses ke halaman ini');
			header('location: '.site_url().'/login');
		}else{

			$this->data['cookie'] = $this->account->get_cookie();
		}
	}

	public function index(){

		$id = $this->data['cookie']['c_username'];
		
		
		$this->data['artikel']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_home';
		$this->data['title'] = 'Halaman Admin';
		
		$this->load->view('admin_panel', $this->data);
	}

	public function artikel(){

		$id = $this->data['cookie']['c_username'];

		$this->data['artikel']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_artikel';
		$this->data['title'] = 'Artikel';
		$this->load->view('admin_panel', $this->data);
	}

	public function produk(){

		$id = $this->data['cookie']['c_username'];

		$this->data['produk']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_produk';
		$this->data['title'] = 'Produk';
		$this->load->view('admin_panel', $this->data);
	}

	public function komentar(){

		$id = $this->data['cookie']['c_username'];

		$this->data['komentar']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_komentar';
		$this->data['title'] = 'Komentar';
		$this->load->view('admin_panel', $this->data);
	}

  public function pesanan(){

		$this->load->model('panel_pesanan');

		$this->data['pesanan']  = $this->pesanan->get_pesanan();
		$this->data['page']  = 'panel_pesanan';
		$this->data['title'] = 'Daftar Pemesanan';
		
		$this->load->view('admin_panel', $this->data);
	}
	public function hubungikami(){

		$id = $this->data['cookie']['c_username'];

		$this->data['hubungikami']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_hubungikami';
		$this->data['title'] = 'Hubungi Kami';
		$this->load->view('admin_panel', $this->data);
	}

	public function statistik(){

		$id = $this->data['cookie']['c_username'];

		$this->data['statistik']  = $this->account->get_admin($id);
		$this->data['page']  = 'panel_statistik';
		$this->data['title'] = 'Statistik';
		$this->load->view('admin_panel', $this->data);
	}
	public function logout(){

		$this->account->do_logout();
		header('location: '.site_url().'/login');
	}
}		